/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.baatar.opt.pga.impl.client;

import org.baatar.net.client.TCPClient;
import org.baatar.opt.genetic.AlgorithmParameters;
import org.baatar.opt.genetic.chromosome.MigrantChromosome;
import org.baatar.opt.pga.intf.IPGACoordinator;
import org.baatar.remoting.message.RemoteRequest;
import org.baatar.remoting.service.RemotingServiceInfo;

/**
 *
 * @author Ba
 */
public class PGACoordinatorConnection<T, M> extends TCPClient implements IPGACoordinator<T, M> {

    @Override
    public Integer registerCluster(RemotingServiceInfo clusterNetInfo, Integer numOfWorkers) throws Exception {
        return sendMessage(new RemoteRequest(callerInfo, "registerCluster", clusterNetInfo, numOfWorkers), Integer.class).getResult();
    }

    @Override
    public void reportProgress(Integer clusterIndex, Integer optimizerIndex, Integer iteration, String progress) throws Exception {
        sendMessage(new RemoteRequest(callerInfo, "reportProgress", clusterIndex, optimizerIndex, iteration, progress), Void.class).getResult();
    }

    @Override
    public AlgorithmParameters<T, M> getAlgorithmParameters() throws Exception {
        return sendMessage(new RemoteRequest(callerInfo, "getAlgorithmParameters"), AlgorithmParameters.class).getResult();
    }

    @Override
    public void migrate(Integer clusterIndex, Integer optimizerIndex, Integer iteration, MigrantChromosome<M> migrants[]) throws Exception {
        sendMessage(new RemoteRequest(callerInfo, "migrate", clusterIndex, optimizerIndex, iteration, migrants), Void.class);
    }
}
